package com.aishau.smartbj.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;

import com.aishau.smartbj.R;
import com.aishau.smartbj.utils.CacheUtils;

/**
 * Created by aishua on 2017/7/20.
 */

public class SplashActivity extends Activity {

    public static final String START_MAIN = "start_main";
    private RelativeLayout re_splash_root;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        re_splash_root = (RelativeLayout) findViewById(R.id.re_splash_root);

        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);


        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(rotateAnimation);
        animationSet.setDuration(1000);
        animationSet.setAnimationListener(new MyAnimationListener());
        re_splash_root.startAnimation(animationSet);

    }

    public class MyAnimationListener implements Animation.AnimationListener {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {

            boolean isStartMain = CacheUtils.getBoolean(SplashActivity.this, START_MAIN);
            Intent intent;
            if (isStartMain) {
//                 直接进入主页面
                intent = new Intent(SplashActivity.this, MainActivity.class);
            } else {

//               进入引导页面
                intent = new Intent(SplashActivity.this, GuideActivity.class);

            }
            startActivity(intent);
            finish();

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    }
}
